<?php


namespace Production\Controller;

use Think\Controller;

/**
 * Class IndexController
 * @package Production\Controller
 * @郑钟良
 */
class IndexController extends Controller
{
    public function _initialize(){
        $this->setTitle('制片');
    }
    public function index($page=1){
        //推荐帮忙ids
        $recommendIds = D('ProductionRecommend')->field('help_id')->select();
        $recommendIds = array_column($recommendIds, 'help_id');
        //校园成员ids
        $memberIds = D('Member')->where(array('is_production' => 1))->field('uid')->select();
        $memberIds = array_column($memberIds, 'uid');
        $helpList = D('Help/Help')->getHelpListByUids($memberIds,$page,$totalCount,$recommendIds);
        $this->assign('productionList',$helpList);
        $this->assign('totalCount',$totalCount);
        $this->display();
    }
    public function member($page = 1)
    {
        $model = D('Member');
        $map['status'] = 1;
        $map['last_login_time'] = array('neq', 0);
        $map['is_production'] = 1;
        $memberList = $model->where($map)->field('uid')->page($page, 50)->select();
        $totalCount = $model->where($map)->count();
        foreach ($memberList as &$v) {
            $v = query_user(array('uid','avatar128', 'space_url', 'fans', 'nickname','doing','address','help_count','sex','rank_link','sentiment','rate','user_help_3'), $v['uid']);


            $v['verify_info']=verify_info($v['uid']);
        }
        unset($v);
        $this->assign('memberList', $memberList);
        $this->assign('totalCount', $totalCount);
        $this->setTitle('制片大神页面');
        $this->display();
    }

    public function apply()
    {
        $uid = is_login();
        $isProduction = query_user(array('is_production'), $uid);
        $data['status'] = 0;
        $data['isAlready'] = 0;
        $data['succ'] = 1;
        if ($isProduction['is_production'] == 0) {
            $data['status'] = 1;
            $map['uid'] = $uid;
            $map['status'] = 0;
            $isApply = D('ProductionAudit')->where($map)->count();
            if ($isApply) {
                $data['isAlready'] = 1;
            } else {
                if (!(D('ProductionAudit')->where(array('uid' => $uid))->setField('status', 0))) {
                    if (!(D('ProductionAudit')->add($map))) {
                        $data['succ'] = 0;
                    }
                }
            }
        }
        $this->ajaxReturn($data);
    }
}